import { dictionaryByName } from "$api/dictionary"
import { getPagination, newgetDataGrid } from "$utils/table"

export default {
  data() {
    return {

      dataGrid: {
        // 没有数据时显示新增按钮
        nodataDisplayAdd: true,
        // 1 加载中 2 加载完成有数据 3 加载完成没有数据
        loading: 1,

        trigger: false,
        data: [],
        pagination: {
          // 每页数量
          pageSize: 1000,
          // 当前页数
          pageNum: 1,
          // 总页数
          sumPageNum: ""
        },
        columns: [

          {
            prop: "taskName",
            label: "任务名称"
          },
          {
            prop: "taskType",
            label: "类型"
          },

          {
            prop: "priorityStr",
            label: "优先级",
          },
          {
            prop: "planTime",
            label: "规划时间"
          },
          {
            prop: "remark",
            label: "备注"
          }
        ]
      }
    }
  },
  methods: {
    async search() {
      const _form = getPagination({
        dicName: "taskType",
      }, this.dataGrid)

      await newgetDataGrid(this.dataGrid, dictionaryByName, _form, false, data => {
        this.dataGrid.data = data.map(item => {
          const { selectBg, selctColor } = JSON.parse(item.remark) || {}

          return {
            ...item,
            statusName: !item.status ? "启用" : "禁用",
            selctColor,
            selectBg
          }
        })
      })
      console.log(this.dataGrid.data);
    },
    swipeClick(content, index, item) {
      const { EDIT, REMOVE } = this.basicFlag
      if (index === 0) {
        this.pageSkip(item, EDIT)
      } else if (index === 1) {
        this.openDialog(item, REMOVE)
      }
    }
  }

}
